import request from '@/utils/request'

interface LoginParams {
  medical_record_number: string
  id_last_six: string
}

export interface UserInfo {
  user_id: number
  medical_record_number: string
  name: string
  gender: string
  dob: string
  id_card_number: string
  phone_number: string
  address: string
  id_last_six: string
}

export interface LoginResponse {
  status: string
  code: number
  message: string
  payload: {
    access_token: string
    token_type: string
    is_admin: boolean
    user_info?: {
      user_id: string
      medical_record_number: string
      inpatient_number: string
      name: string
      bed_number: string
      gender: string
      dominant_hand: string
      diagnosis: string
      id_last_six: string
      dob: string
      height_cm: number
      contact: string
      weight_kg: number
      education_level: string
      education_years: number
      remarks: string
    }
  }
}

export const login = (data: LoginParams): Promise<LoginResponse> => {
  return request({
    url: '/v3/auth/login',
    method: 'post',
    data,
  })
}

interface RegisterParams {
  id_last_six: string
  name: string
  gender: string
  dominant_hand: string
  diagnosis: string
  dob: string
  height_cm: number
  weight_kg: number
  contact: string
  education_level: string
  education_years: number
  remarks: string
}

export interface RegisterResponse {
  status: string
  code: number
  message: string
  data: {
    access_token: string
    token_type: string
    is_admin: boolean
    user_id: string
    medical_record_number: string
    name: string
    gender: string
    dominant_hand: string
    diagnosis: string
    id_last_six: string
    dob: string
    height_cm: number
    contact: string
    weight_kg: number
    education_level: string
    education_years: number
    remarks: string
    login_qr_code: string
  }
}

export const register = (data: RegisterParams): Promise<RegisterResponse> => {
  return request({
    url: '/v1/register',
    method: 'post',
    data,
  })
}
